package models

import (
	"github.com/astaxie/beego/orm"
)

type ArticleType struct {
	Id   int64
	Name string `orm:"uinque;size(60)" form:"name" valid:"Required;MinSize(2);MaxSize(60)"`
}

//自定义模型(表名)
func (a *ArticleType) TableName() string {
	return "yii2_article_type"
}

//初始化
func init() {
	orm.RegisterModel(new(ArticleType))
}

//获取文章类别
func GetArtTypeList() (artTypes []orm.Params) {
	o := orm.NewOrm()
	sql := "select art.type_id as id,tp.name,count(*) as total from yii2_article as art left join yii2_article_type as tp on art.type_id=tp.id where art.status_is = 1  group by art.type_id"
	o.Raw(sql).Values(&artTypes)
	return artTypes
}
